//
//  UserAccount.swift
//  weibo
//
//  Created by hm on 2020/5/3.
//  Copyright © 2020 hm. All rights reserved.
//

import UIKit

class UserAccount: NSObject {
    // MARK:- 属性
    var access_token : String = ""
    var expires_in : TimeInterval = 0 {
      didSet {
          expires_date = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    
    var uid : String = ""
    
    var expires_date : NSDate = NSDate()
    var avatar_large : String = "" {
        didSet {
            avatar_url = URL(string: avatar_large)
        }
    }
    var screen_name : String = ""
    var avatar_url : URL?
    
    // MARK:- 构造函数
    //根据网络请求返回的字典类型初始化
    init(dict : [String : AnyObject]) {
        super.init()
        
        access_token = dict["access_token"] as! String
        expires_in = dict["expires_in"] as! TimeInterval
        uid = dict["uid"] as! String
        
    }
    
    //忽略字典中未定义的字段
    override func setValue(_ value: Any?, forUndefinedKey key: String) { }

    //重写tostring
    override var description : String {
        //将类的属性转换为字典类型
        return "access_token:{self.access_token}"
    }
    
}
